package com.bruce.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bruce.dao.UserDao;
import com.bruce.model.User;
import com.bruce.service.UserService;
import com.bruce.tool.JWBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;
	@Override
	public int insert(User impl) {
		// TODO Auto-generated method stub
		return userDao.insert(impl);
	}

	@Override
	public int update(User impl) {
		// TODO Auto-generated method stub
		return userDao.update(impl);
	}

	@Override
	public PageInfo<User> selectAll(int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageNum, pageSize);
		return new PageInfo<User>(userDao.selectAll());
	}

	@Override
	public boolean isPermission(int userid, String url) {
		// TODO Auto-generated method stub
		List<Integer> num = userDao.isPermission(userid, url);
		if(null == num || num.size() == 0) {
			return false;
		}
		if(1 == num.size() ) {
			return true;
		}
		return false;
	}

	@Override
	public int getId(User impl) {
		// TODO Auto-generated method stub
		return userDao.getId(impl);
	}

	@Override
	public User getUserInfoByname(String nickname) {
		// TODO Auto-generated method stub
		return userDao.getUserInfoByname(nickname);
	}
	/**
	 * 更改用户最后登入时间
	 */
	public void setLastLoginTime(User userImpl) {
		userImpl.setPswd(null);
		userImpl.setLast_login_time(JWBean.getNowDateByFormat("yyyy-MM-dd HH:mm:ss"));
		userDao.update(userImpl);
	}
}
